<!doctype html>
<html>
<head>
<meta name="Generator"  />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>添加收货地址</title>
<meta name="Keywords" content="Call管家" />
<meta name="Description" content="Call管家" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>

<link rel="stylesheet" href="__HOMECSS__/style.css">
<link rel="stylesheet" type="text/css" href="__HOMECSS__/mobileSelect.css">
<script src="__HOMEJS__/mobileSelect1.js" type="text/javascript"></script>
</head>

<body >
<div class="add_address">
    <span>收货人</span>
    <input type="text" name='consignee' id='consignee' placeholder="请输入" value="{$address_info.consignee}">
</div>
<div class="add_address">
    <span>联系电话</span>
    <input type="text" name='mobile' id='mobile' placeholder="请输入" value="{$address_info.mobile}">
</div>
<div class="add_address">
    <span>所在地区</span>
    <div><span id="trigger5">{if condition='($address_info[province] eq null && $address_info[city] eq null && $address_info[district] eq null)'}请选择{else /}{$address_info.province}{$address_info.city}{$address_info.district}{/if}</span> <img src="__HOMEIMG__/productlist_icon_23.png" alt="" width="100%"></div>
    <input type='hidden' name='province' id='province' value="{$address_info.province}">
    <input type='hidden' name='city' id='city' value="{$address_info.city}">
    <input type='hidden' name='district' id='district' value="{$address_info.district}">
    <input type='hidden' name='id' id='id' value="{$address_info.id}">
</div>
<textarea placeholder="请填写详细地址，不少于5个字" class="address_textarea" name='address' id='address' >{$address_info.address}</textarea>
<div class="address_set">
    <span><input type="radio" name='is_default' id='is_default' value="1" {if condition='($address_info[is_default] eq 1) or $address_info[is_default] eq null'}checked{/if}><span>设为默认</span></span>
</div>
<div class="address_new">
    <p>添加</p>
</div>
</body>
<script src="__HOMEJS__/jquery-1.7.2.min.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script type="text/javascript">
    var UplinkData =
        [
           {volist name="region" id="val"}
            {
                id:'{$val.id}',
                value:'{$val.name}'
                {if condition='($val[city] neq null)'}
                   ,childs:[
                       {volist name="val.city" id="vo"}
                        {
                           id:'{$vo.id}',
                            value:'{$vo.name}'
                            {if condition='($vo[district] neq null)'}
                            ,childs:[
                              {volist name="vo.district" id="v"}
                                {
                                    id:'{$v.id}',
                                    value:'{$v.name}',
                                },
                              {/volist}
                            ]
                           {/if}
                         },
                         {/volist}
                   ]
                {/if}
            },
           {/volist}
           
        ];


    var mobileSelect5 = new MobileSelect({
        trigger: '#trigger5',

        wheels: [
            {data : UplinkData}
        ],
        transitionEnd:function(indexArr, data){
            console.log(data);
        },
        callback:function(indexArr, data){
            console.log(data);
            var id1 = data[0].id;
            var id2 = data[1].id;
            var id3 = data[2].id;
            $("#province").val(id1);
            $("#city").val(id2);
            $("#district").val(id3);
        },
       
        
    });
 //地址提交
   $(".address_new").click(function () {
       var id = $("#id").val();
       var consignee = $("#consignee").val();
       var mobile = $("#mobile").val();
       var province = $("#province").val();
       var city = $("#city").val();
       var district = $("#district").val();
       var address = $("#address").val();
       var is_default = $('input[name="is_default"]:checked ').val();
       var url = "";
       if(id){
          url = "{:Url('User/edit_address')}";
       }else{
          url = "{:Url('User/add_address')}";
       }
        $.ajax({
                type:"post",
                url:url,
                dataType:'json',
                data:{"id":id,"consignee":consignee,"mobile":mobile,"province":province,"city":city,"district":district,"address":address,"is_default":is_default},
                success:function(result){
                       if(result.status==1){
                            layer.msg(result.info,{icon:1,time:1500});
                            if(id){
                                window.location.reload();
                            }else{
                                if("{:input('param.is_cart')}" == ""){
                                    window.location.href = "{:Url('User/address')}";
                                }else{
                                    window.location.href = "{:Url('Order/address')}";
                                }

                            }
                            
                        }else{
                            layer.msg(result.info,{icon:2,time:1500});
                        }
                }
        });
   });
</script>

</html>
